#include <iostream>
#include <cstring>
using namespace std;
const int N=110;

int dp[N][N];

bool is_match(char left,char right)
{
	if(left=='(' && right==')')
		return true;
	if(left=='[' && right==']')
		return true;
	return false;
}
int main()
{
	string s;
	getline(cin,s);
	int n=s.size();
	for(int len=1;len<=n;len++)
	{
		for(int i=0;i+len-1<n;i++)
		{
			int j=i+len-1;
			dp[i][j]=0x3f3f3f3f;
			if(is_match(s[i],s[j]))
				dp[i][j]=dp[i+1][j-1];
			dp[i][j]=min(dp[i][j],dp[i][j-1]+1);
			dp[i][j]=min(dp[i][j],dp[i+1][j]+1);
			for(int k=i;k<j;k++)
			{
				dp[i][j]=min(dp[i][j],dp[i][k]+dp[k+1][j]);
			}
			
		}
	}
	cout<<dp[0][n-1]<<endl;
	return 0;
}
